home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
edit
/
pt20pc.zip
/
GETINPUT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-02-04
|
20KB
|
763 lines
#include "pt.h"
#include "string.h"
#include "direct.h"
#include "conio.h"
static unsigned char buffer[101];
static int nameRow, nameCol;
static int buttonState;
static int space;
static int maxNameSize;
unsigned char * pascal
/* XTAG:getFileName */
getFileName(prompt)
unsigned char *prompt;
{
extern union REGS rin, rout;
extern unsigned char filePattern[];
extern unsigned char msgBuffer[];
extern unsigned char textBuffer[];
extern unsigned char fsPatterns[];
extern unsigned char fsDirs[];
extern unsigned char scratchFileName[];
extern int scrRows, scrCols;
extern unsigned char bannerColor;
extern unsigned char textColor, selColor;
extern unsigned char scrMapReset;
extern int debug;
extern int fsMenu;
extern int fileSort;
extern unsigned int dispMemory;
extern struct SREGS segRegs;
extern struct menuBlock far *menus[];
extern unsigned char startDirectory[];
extern unsigned char startDrive;
extern int helpMode;
extern unsigned char currentDirectory[];
extern unsigned char currentDrive;
extern int addHandle;
unsigned char *fileName = NULL, *p, *q, *fileMarks;
unsigned char extension[3];
unsigned char far *fp;
unsigned int *ip;
int i, k, n, row, col, ret, iBuffer, fileCount;
int firstName, lastName;
int maxFiles, extensionLength;
int maxCol, offset;
int saveRow, saveCol;
int gettingDirectories;
int saveHelpMode;
struct SREGS sr;
int selectedRow, selectedCol;
/* use the current directory that the user set last */
setDefaultDrive(currentDrive);
chdir(currentDirectory);
/* set up so we know when to allocate space again */
space = 0;
saveHelpMode = helpMode;
helpMode = 0;
restart:
msg("***** Please wait while directory is read *****", 1);
maxNameSize = 1;
maxFiles = 512;
while( 1 ) {
/* get some space to put the names in */
if( space == 0 ) {
rin.h.ah = 0x48;
rin.x.bx = 4 * maxFiles; /* 16-byte paragraphs */
intdos(&rin, &rout);
n = rout.x.cflag;
if( n & 0x1 ) {
maxFiles >>= 1; /* divide by 2 */
if( maxFiles > 8 )
continue;
msg("No space to sort file names", 3);
fileName = NULL;
space = 0;
goto askName;
}
space = rout.x.ax;
}
break;
}
/* find the names */
fileCount = 0;
/* first get all the directories */
gettingDirectories = 1;
fileName = findFirstPatternFile( "*.*", 0x10, buffer );
while( fileCount < maxFiles ) {
if( fileName == NULL ) {
/* for some reason I can't figure out. The directory search fails when */
/* I remove this statement. So I left it in. */
if( debug==91 ) { setCPos(23,0);cprintf(" %d ", fileCount); }
/* are we done or just done with the directories? */
if( gettingDirectories ) {
gettingDirectories = 0;
fileName = findFirstPatternFile( filePattern,
0x1, buffer );
continue;
} else
break;
}
/* put in the string that defines the sort order (1st char) */
/* and marked the file type (2nd char) */
if( gettingDirectories ) {
if( (buffer[21]&0x10) != 0 ) /* a directory */
/* directories will sort to the beginning */
fileMarks = "DD";
else
/* get only directories this pass */
goto getNextFileName;
} else {
if( (buffer[21]&0x3) != 0 )
/* hidden or read-only files */
fileMarks = "ZH";
else
fileMarks = "ZN";
}
/* move the name into the buffer */
offset = 64 * fileCount;
/* put in the char to make directories sort in front */
movedata(segRegs.ds, (int)fileMarks, space, offset++, 1);
if( fileSort == 2 ) {
/* find the extension */
q = NULL;
p = &buffer[30];
while( *p != '\0' ) {
if( *p == '.' )
q = p;
++p;
}
/* found a '.' that was not a ".."? */
i = 0;
if( q != NULL && buffer[30] != '.' ) {
/* remove the extension from the name by */
/* overlaying the '.' with end-of-string */
*q++ = '\0';
/* get the extension */
while( *q != '\0' )
extension[i++] = *q++;
}
/* pad extension with blanks */
extensionLength = i;
while( i < 3 )
extension[i++] = ' ';
movedata(segRegs.ds, (int)(&extension[0]), space,
offset, 3);
offset += 3;
}
n = strlen(fileName) + 1; /* + 1 for the '\0' */
if( fileSort == 2 && extensionLength > 0 ) {
n -= (extensionLength + 1);
/* +1 for the "." */
/* erase the extension from fileName */
fileName[n - 1] = '\0';
}
/* put in the file type chararacter */
fileName[n] = *(fileMarks + 1);
movedata( segRegs.ds, (int)fileName, space, offset, n+1 );
k = n + 1; /* extra +1 for spacing on screen */
if( k > maxNameSize )
maxNameSize = k;
++fileCount;
getNextFileName:
/* find the next matching file name */
fileName = findNextPatternFile(buffer);
}
/* adjust for the size of the extension if sorting by extension */
if( fileSort == 2 )
maxNameSize += 4;
/* sort the names */
if( fileSort != 0 ) {
for(k = 1; k < fileCount; k++) {
movedata(space, 64*k, segRegs.ds, (int)(&msgBuffer[0]),
maxNameSize);
i = k-1;
while( i >= 0 ) {
movedata(space, 64*i, segRegs.ds,
(int)(&textBuffer[0]), maxNameSize);
if( strcmp(textBuffer, msgBuffer) <= 0 )
break;
movedata(segRegs.ds, (int)(&textBuffer[0]),
space, 64*(i+1), maxNameSize);
i--;
}
movedata(segRegs.ds, (int)(&msgBuffer[0]), space, 64*(i+1),
maxNameSize);
}
}
firstName = 0;
selectedRow = 0;
selectedCol = 0;
doPaging:
/* clear the screen buffer where the names will go */
setMap(0, 0, scrRows-2, scrCols-1, 2, textColor);
/* fill in the names */
n = firstName;
/* maxNameSize has two blanks included in it so adjust for that */
maxCol = scrCols - (maxNameSize - 2);
for(col = 0; col < maxCol; col += maxNameSize) {
for(row = 2; row < scrRows-1; row++) {
if( n >= fileCount ) {
lastName = fileCount;
goto displayNames;
}
movedata(space, 64*n, segRegs.ds,
(int)(&textBuffer[0]), 64);
k = 0; /* k counts screen character positions */
if( textBuffer[0] == 'D' )
ret = selColor; /* directory */
else
ret = textColor; /* ordinary file */
/* is this filename selected? */
if( row == selectedRow && col == selectedCol )
ret = selColor; /* selected */
else
ret = textColor; /* not selected */
i = (fileSort==2) ? 4 : 1;
for( ; textBuffer[i] != '\0'; ++i)
displayChar(row, col+k++,
tolower(textBuffer[i]), ret);
iBuffer = i + 1;
if( fileSort == 2 && textBuffer[1] != ' ' ) {
displayChar(row, col+k++, '.', ret);
for(i = 1; i<4 && textBuffer[i]!=' '; i++)
displayChar(row, col+k++,
tolower(textBuffer[i]), ret);
}
if( textBuffer[iBuffer] == 'D' )
displayChar(row, col+k, '\\', ret);
else if( textBuffer[iBuffer] == 'H' )
displayChar(row, col+k, '*', ret);
++n;
}
}
lastName = n;
displayNames:
/* remember these so that we can detect invalid click locations */
saveRow = row;
saveCol = col;
(void)getcwd(&msgBuffer[0], MSGBUFFERSIZE);
sprintf(textBuffer, "%d files in %s matching %s%s",
fileCount, msgBuffer, filePattern,
(fileCount < maxFiles ? "" : "SOME FILE NAMES MISSING")
);
col = 0;
for(i = 0; textBuffer[i] != '\0' && col < scrCols; i++)
displayChar(1, col++, textBuffer[i], bannerColor);
while( col < scrCols )
displayChar(1, col++, ' ', bannerColor);
pulldown(fsMenu);
updateScreen(0, scrRows-2);
fileName = getInput(prompt, "", 2);
if( fileName != NULL ) /* A string was entered (no mouse button) */
goto processFilename;
/* otherwise we got a mouse click and row and col are set */
/* normalize to first char in field */
if( nameRow > 0 ) {
/* normalize to first character in field */
nameCol = maxNameSize*(nameCol/maxNameSize);
/* see if the click is where we put a file name */
if( (nameCol > saveCol) || (nameRow == scrRows-1)
|| ((nameCol == saveCol) && (nameRow > saveRow)) ) {
/* if not, CD to the parent directory */
strcpy(scratchFileName, "..");
goto changeDirectory;